﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;

namespace AnyOffice.general.info.dept
{
    public partial class index : ModulePage
    {
       protected StringBuilder strDept;
        protected string strTemp;

        private void LoadDeptTree(int DeptId, string strTemp)
        {
            DataTable table = new DepartmentDao().SelectChildAll(base.Conn, DeptId);
            if (table.Rows.Count > 0)
            {
                strTemp = strTemp + "|　";
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    this.strDept.Append("<tr class=\"TableData\">\n");
                    this.strDept.Append("<td>\n");
                    this.strDept.Append(strTemp + "|─" + table.Rows[i]["DeptName"].ToString());
                    this.strDept.Append("</td>\n");
                    this.strDept.Append("<td>\n");
                    this.strDept.Append((table.Rows[i]["TelNo"] != DBNull.Value) ? table.Rows[i]["TelNo"].ToString() : "");
                    this.strDept.Append("</td>\n");
                    this.strDept.Append("<td>\n");
                    this.strDept.Append((table.Rows[i]["FaxNo"] != DBNull.Value) ? table.Rows[i]["FaxNo"].ToString() : "");
                    this.strDept.Append("</td>");
                    this.strDept.Append("<td>\n");
                    this.strDept.Append((table.Rows[i]["DeptFunc"] != DBNull.Value) ? table.Rows[i]["DeptFunc"].ToString() : "");
                    this.strDept.Append("</td>\n");
                    this.strDept.Append("</tr>\n");
                    this.LoadDeptTree(int.Parse(table.Rows[i]["DeptId"].ToString()), strTemp);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.strDept = new StringBuilder();
            DataTable table = new DepartmentDao().SelectParentAll(base.Conn);
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    this.strDept.Append("<tr class=\"TableData\">\n");
                    this.strDept.Append("<td>\n");
                    this.strDept.Append("|─" + table.Rows[i]["DeptName"].ToString());
                    this.strDept.Append("</td>\n");
                    this.strDept.Append("<td>\n");
                    this.strDept.Append((table.Rows[i]["TelNo"] != DBNull.Value) ? table.Rows[i]["TelNo"].ToString() : "");
                    this.strDept.Append("</td>\n");
                    this.strDept.Append("<td>\n");
                    this.strDept.Append((table.Rows[i]["FaxNo"] != DBNull.Value) ? table.Rows[i]["FaxNo"].ToString() : "");
                    this.strDept.Append("</td>");
                    this.strDept.Append("<td>\n");
                    this.strDept.Append((table.Rows[i]["DeptFunc"] != DBNull.Value) ? table.Rows[i]["DeptFunc"].ToString() : "");
                    this.strDept.Append("</td>\n");
                    this.strDept.Append("</tr>\n");
                    this.strTemp = "";
                    this.LoadDeptTree(int.Parse(table.Rows[i]["DeptId"].ToString()), this.strTemp);
                }
            }
        } 

    }
}
